import React from 'react';
// 发送请求
import url from "../config/url"
import req from "../http/req"

import { Redirect } from 'react-router';
const Checklogin = (Cmp) => {
    return class NewCmp extends React.Component{
        state = {
            isLogin: false,
            isFinish: false
        }
        render () {
            return this.state.isFinish ? this.state.isLogin ? <Cmp {...this.props}/> : <Redirect to="/login"/> : <></>
        }
        componentDidMount() {
            req.get(url.JwtCheck).then(res => {
                if(res.data.errNo === 0) {
                    this.setState({
                        isLogin: true,
                        isFinish: true
                    })
                }else {
                    this.setState({
                        isLogin: false,
                        isFinish: true
                    })
                }
            })
        }
    }
}

export default Checklogin;
